package org.jsola.hr.helper;

import org.jsola.hr.dto.RegistrationRecordAddDTO;
import org.jsola.hr.dto.RegistrationRecordUpdateDTO;
import org.jsola.hr.entity.RegistrationRecordDO;
import org.jsola.hr.query.RegistrationRecordQuery;
import org.jsola.hr.service.IRegistrationRecordService;
import org.jsola.hr.vo.RegistrationRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 登录记录
 *
 * @author zhr
 */
@Component
public class RegistrationRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private IRegistrationRecordService registrationRecordService;

    /**
     * 生成add测试数据
     * @return RegistrationRecordAddDTO
     */
    public RegistrationRecordAddDTO getRegistrationRecordAddDTO(){
        RegistrationRecordAddDTO registrationRecordAddDTO = new RegistrationRecordAddDTO();
        registrationRecordAddDTO.setSubjectId(getRandomValue("varchar",32));
        registrationRecordAddDTO.setParentSubjectId(getRandomValue("varchar",32));
        registrationRecordAddDTO.setSubjectType(getRandomValue("varchar",32));
        registrationRecordAddDTO.setParentSubjectType(getRandomValue("varchar",32));
        return registrationRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return RegistrationRecordUpdateDTO
     */
    public RegistrationRecordUpdateDTO getRegistrationRecordUpdateDTO(RegistrationRecordVO registrationRecordVO){
        return registrationRecordService.selectDOById(registrationRecordVO.getId(), SITE_ID).to(RegistrationRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return RegistrationRecordQuery
     */
    public RegistrationRecordQuery getRegistrationRecordQuery() {
        RegistrationRecordQuery registrationRecordQuery = new RegistrationRecordQuery();
        List<RegistrationRecordDO> registrationRecordDOList = registrationRecordService.list(new RegistrationRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(registrationRecordDOList)) {
            RegistrationRecordDO registrationRecordDO = registrationRecordDOList.get(0);
            registrationRecordQuery = registrationRecordDO.to(RegistrationRecordQuery.class);
        }
        return registrationRecordQuery;
    }

    /**
     * 保存示例
     * @return RegistrationRecordVO
     */
    public RegistrationRecordVO saveRegistrationRecordExample(){
        RegistrationRecordAddDTO addDTO = this.getRegistrationRecordAddDTO();
        RegistrationRecordVO registrationRecordVO = registrationRecordService.save(addDTO,buildTokenUser());
        return registrationRecordVO;
    }


}

